﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Distribution.Service;
using DistributionApplication.Controls.Events;
using Entities;

namespace DistributionApplication
{
    public partial class frmTransformerHome : frmBase
    {
        public frmTransformerHome(EPole pole)
        {
            InitializeComponent();
            gridHome.Pole = pole;
        }

        protected override void lblClose_Click(object sender, EventArgs e)
        {
            Close();
        }

        protected override void lblLButton_Click(object sender, EventArgs e)
        {
            frmTransformer transformerForm = new frmTransformer();
            transformerForm.Pole = gridHome.Pole;

            Hide();
            transformerForm.ShowDialog();
            Show();

            gridHome.ReloadGrid();
        }

        private void grdDistributions_ClickedEditTransformer(object sender, GridEventArgs e)
        {
            ETransformer transformer = LTransformer.GetById(e.Id);

            Hide();

            frmTransformer transformerForm = new frmTransformer();
            transformerForm.Pole = gridHome.Pole;
            transformerForm.TransformerToBeLoaded = transformer;
            transformerForm.ShowDialog();

            Show();

            gridHome.ReloadGrid();
        }

        private void grdDistributions_ClickedRemoveTransformer(object sender, GridEventArgs e)
        {
            ETransformer selectedTransformer = new ETransformer();
            selectedTransformer.Id = e.Id;

            Hide();
            LTransformer.Delete(selectedTransformer);
            Show();

            gridHome.ReloadGrid();
        }

        private void frmTransformerHome_Load(object sender, EventArgs e)
        {
            Title = "PPI | Transformers";

            RButtonText = "Cancel";
            gridHome.ConfigureGrid();

            LButtonText = "New";
        }

        protected override void lblRButton_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}